home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / dostech.arc / CHAP8 < prev    next >
Text File  |  1989-02-04  |  30KB  |  612 lines

  1. CHAPTER 8
  2.  
  3.  Programming Technical Reference - IBM
  4.  Copyright 1988, Dave Williams
  5.  
  6.                           DOS DISK INFORMATION
  7.  
  8.  
  9. THE DOS AREA
  10.  
  11.  All disks and diskettes formatted by DOS are created with a sector size of 512
  12. bytes. The DOS area (entire area for a diskette, DOS partition for hard disks)
  13. is formatted as follows:
  14.  
  15.         Boot record - 1 sector
  16.         First copy of the FAT - variable size
  17.         Second copy of the FAT - same size as first copy
  18.         Root directory - variable size
  19.         Data area
  20.  
  21. The following sections describe each of the allocated areas: 
  22.  
  23.  
  24. THE BOOT RECORD
  25.  
  26.  The boot record resides on track 0, sector 1, side 0 of every diskette 
  27. formatted by the DOS FORMAT program. It is put on all disks to provide an error
  28. message is you try to start up with a nonsystem disk in drive A:. For hard disks
  29. the boot record resides on the first sector of the DOS partition.
  30.  
  31.  
  32. THE DOS FILE ALLOCATION TABLE (FAT)
  33.  
  34.  This section explains how DOS uses the FAT to convert the clusters of a file 
  35. into logical sector numbers. We recommend that system utilities use the DOS 
  36. handle calls rather than interpreting the FAT.
  37.  
  38.  The FAT is used by DOS to allocate disk space for files, one cluster at a time.
  39.  
  40.  The FAT consists of a 12 bit entry (1.5 bytes) for each cluster on the disk or
  41. a 16 bit (2 bytes) entry when a hard disk has more than 20740 sectors as is the
  42. case with fixed disks larger than 10Mb.
  43.  The first two FAT entries map a portion of the directory; these FAT entries 
  44. contain indicators of the size and format of the disk. The FAT can be in a 12 
  45. or 16 bit format. DOS determines whether a disk has a 12 or 16 bit FAT by 
  46. looking at the total number of allocation units on a disk. For all diskettes 
  47. and hard disks with DOS partitions less than 20,740 sectors, the FAT uses a 12 
  48. bit value to map a cluster. For larger partitions, DOS uses a 16 bit value.
  49.  The second, third, and fourth bit applicable for 16 bit FAT bytes always 
  50. contains 0FFFFh. The first byte is used as follows:
  51.  
  52.      hex value              meaning                     normally used
  53.  
  54.        0F8h      hard disk                         bootable hard disk at C:800
  55.                  double sided  18 sector diskette   PS/2 1.44 meg DSQD
  56.        0F9h      double sided  15 sector diskette   AT 1.2 meg DSQD
  57.                  double sided  9  sector diskette   Convertible 720k DSHD
  58.        0FCh      single sided  9  sector diskette   DOS 2.0, 180k SSDD
  59.        0FDh      double sided  9  sector diskette   DOS 2.0, 360k DSDD
  60.        0FEh      single sided  8  sector diskette   DOS 1.0, 160k SSDD
  61.        0FFh      double sided  8  sector diskette   DOS 1.1, 320k SSDD
  62.  
  63.  
  64. The third FAT entry begins mapping the data area (cluster 002).
  65.  
  66. NOTE: These values are provided as a reference. Therefore, programs should not 
  67.       make use of these values.
  68.  
  69.  Each entry contains a hexadecimal character (or 4 for 16 bit FATs). () 
  70. indicates the high order four bit value in the case of 16 bit FAT entries. 
  71. They can be:
  72.  
  73.             (0)000h  if the cluster is unused and availible
  74.  
  75. (0F)FF8h - (0F)FFFh  to indicate the last cluster of a file
  76.  
  77.             (X)XXXh  any other hexadecimal numbers that are the cluster number
  78.                      of the next cluster in the file. The cluster number is the
  79.                      first cluster in the file that is kept in the file's 
  80.                      directory entry.
  81.  
  82.  The values (0F)FF0h - (0F)FF7h are used to indicate reserved clusters. 
  83. (0F)FF7h indicates a bad cluster if it is not part of the allocation chain. 
  84. (0F)FF8h - (0F)FFFh are used as end of file markers.
  85.  
  86.  The file allocation table always occupies the sector or sectors immediately 
  87. following the boot record. If the FAT is larger than 1 sector, the sectors 
  88. occupy consecutive sector numbers. Two copies of the FAT are written, one 
  89. following the other, for integrity. The FAT is read into one of the DOS buffers
  90. whenever needed (open, allocate more space, etc).
  91.  
  92.  
  93. USE OF THE 12 BIT FILE ALLOCATION TABLE
  94.  
  95. Obtain the starting cluster of the file from the directory entry.
  96.  
  97. Now, to locate each subsequent sector of the file:
  98.  
  99. 1. Multiply the cluster number just used by 1.5 (each FAT entry is 1.5 
  100.    bytes long).
  101. 2. The whole part of the product is offset into the FAT, pointing to the entry 
  102.    that maps the cluster just used. That entry contains the cluster number of 
  103.    the next cluster in the file.
  104. 3. Use a MOV instruction to move the word at the calculated FAT into a register.
  105. 4. If the last cluster used was an even number, keep the low order 12 bits of 
  106.    the register, otherwise, keep the high order 12 bits.
  107. 5. If the resultant 12 bits are (0FF8h-0FFFh) no more clusters are in the file.
  108.    Otherwise, the next 12 bits contain the cluster number of the next cluster in
  109.    the file. 
  110.  
  111.   To convert the cluster to a logical sector number (relative sector, such as 
  112. that used by int 25h and 26h and DEBUG):
  113.  
  114. 1. Subtract 2 from the cluster number
  115. 2. Multiply the result by the number of sectors per cluster.
  116. 3. Add the logical sector number of the beginning of the data area.
  117.  
  118.  
  119. USE OF THE 16 BIT FILE ALLOCATION TABLE
  120.  
  121.  Obtain the starting cluster of the file from the directory entry. Now to 
  122. locate each subsequent cluster of the file:
  123.  
  124. 1.  Multiply the cluster number used by 2 (each FAT entry is 2 bytes long).
  125. 2.  Use the MOV word instruction to move the word at the calculated FAT offset 
  126.     into a register.
  127. 3.  If the resultant 16 bits are (0FF8h-0FFFFh) no more clusters are in the 
  128.     file. Otherwise, the 16 bits contain the cluster number of the next cluster 
  129.     in the file. 
  130.  
  131.  Compaq DOS makes availible a new disk type (6) with 32 bit partition values, 
  132. allowing 512 megabytes per hard disk (Compaq DOS 3.3.1)
  133.  
  134.  
  135.  
  136. DOS DISK DIRECTORY
  137.  
  138.  The FORMAT command initially builds the root directory for all disks. Its 
  139. location (logical sector number) and the maximum number of entries are 
  140. availible through the device driver interfaces.
  141.  
  142.  
  143.  
  144. DIRECTORY ENTRIES 
  145.  
  146.  Since directories other than the root directory are actually files, there is 
  147. no limit to the number of entries that they may contain. 
  148.  
  149.  All directory entries are 32 bytes long, and are in the following format (byte
  150. and offset are decimal). The following paragraphs describe the directory entry 
  151. bytes:
  152.  
  153. *BYTES 0-7
  154.  Bytes 0-7 represent the filename. The first byte of the filename indicates the 
  155. status of the filename. The status of a filename can contain the following 
  156. values:
  157.  
  158.    00h Filename never used. This is used to limit the length of directory 
  159.        searches, for performance reasons.
  160.    05h Indicates that the first character of the filename actually has an 0Edh 
  161.        character.
  162.   0E5h Filename has been used but the file has been erased.
  163.    2Eh This entry is for a directory. If the second byte is also 2Eh, the 
  164.        cluster field contains the cluster number of this directory's parent 
  165.        directory.  (0000h if the parent directory is the root directory).
  166.                                                  
  167. Any other character is the first character of a filename.
  168.  
  169. *BYTES 8-10
  170.  These bytes indicate the filename extension.
  171.  
  172. *BYTE 11
  173.  This byte indicates the file's attribute. The attribute byte is mapped as 
  174.  follows (values are in hexadecimal):
  175.  
  176. NOTE: Attributes 08h and 10h cannot be changed using function call 43h (CHMOD).
  177.  
  178.  The system files IBMBIO.COM and IBMDOS.COM (or customized equivalent) are 
  179. marked as read-only, hidden, and system files. Files can be marked hidden when 
  180. they are created. Also, the read-only, hidden, and system and archive attributes
  181. may be changed through the CHMOD function call.
  182.  
  183. 01h Indicates that the file is marked read-only. An attempt to open the file 
  184.     for output using function call 3Dh results in an error code being returned. 
  185.     This value can be used with other values below.
  186.  
  187. 02h Indicates a hidden file. The file is excluded from normal directory 
  188.     searches.
  189.  
  190. 04h Indicates a system file. This file is excluded from normal directory 
  191.     searches.
  192.  
  193. 08h Indicates that the entry contains the volume label in the first 11 bytes. 
  194.     The entry contains no other usable information and may exist only in the 
  195.     root directory.
  196.  
  197. 20h Indicates an archive bit. This bit is set on whenever the file is written 
  198.     to and closed. It is used by BACKUP and RESTORE.
  199.  
  200. All other bits are reserved, and must be 0.
  201.  
  202. *BYTES 12-21
  203.  reserved by DOS
  204.  
  205.  
  206. *BYTES 22-23
  207.  These bytes contain the time when the file was created or last updated. The 
  208. time is mapped in the bits as follows:
  209.       ┌───────────────────────────────┬───────────────────────────────┐
  210.       │         B Y T E    23         │         B Y T E    22         │
  211.       ├───────────────────────────────┼───────────────────────────────┤
  212.       │ F   E   D   C   B   A   9   8 │ 7   6   5   4   3   2   1   0 │
  213.       ├───────────────────┬───────────┴───────────┬───────────────────┤
  214.       │ H   H   H   H   H │ M   M   M   M   M   M │ D   D   D   D   D │
  215.       ├───────────────────┼───────────────────────┼───────────────────┤
  216.       │ binary # hrs 0-23 │ binary # minutes 0-59 │ bin. # 2-sec incr │
  217.       └───────────────────┴───────────────────────┴───────────────────┘
  218.  
  219. NOTE: The time is stored with the least significant byte first.
  220.  
  221.  
  222. *BYTES 24-25
  223.  This area contains the date when the file was created or last updated. The 
  224. mm/dd/yy are mapped in the bits as follows:
  225.  
  226.       ┌───────────────────────────────┬───────────────────────────────┐
  227.       │         B Y T E    25         │         B Y T E    24         │
  228.       ├───────────────────────────────┼───────────────────────────────┤
  229.       │ F   E   D   C   B   A   9   8 │ 7   6   5   4   3   2   1   0 │
  230.       ├───────────────────────────┬───┴───────────┬───────────────────┤
  231.       │ Y   Y   Y   Y   Y   Y   Y │ M   M   M   M │ D   D   D   D   D │
  232.       ├───────────────────────────┼───────────────┼───────────────────┤
  233.       │      0-119 (1980-2099)    │     1-12      │       1-31        │
  234.       └───────────────────────────┴───────────────┴───────────────────┘
  235.  
  236. NOTE: The date is stored with the least significant byte first.
  237.  
  238.  
  239. *BYTES 26-27
  240.  This area contains the starting cluster number of the first cluster in the 
  241. file. The first cluster for data space on all fixed disks and floppy disks is 
  242. always cluster 002. The cluster number is stored with the least significant 
  243. byte first.
  244.  
  245.  
  246. *BYTES 28-31
  247.  This area contains the file size in bytes. The first word contains the low 
  248. order part of the size. Both words are stored with the least significant byte 
  249. first.
  250.  
  251.  
  252.                         File Allocation Table
  253. offset size                  description
  254.    3       8 bytes system id (such as IBM 3.3)
  255.   11      2 bytes number of bytes per sector, ie 512 bytes is 200h
  256.   13      1 byte  sectors per cluster (1 or 2)
  257.   14      2 bytes number of reserved sectors at beginning, 1 for floppies
  258.   16      1 byte  number of copies of FAT, 2 for floppies
  259.   17      2 bytes number of root directory entries (64, 112, 256,etc)
  260.   19      2 bytes total sectors per disk
  261.   21      1 byte  format ID (F8, F9, FC, FF, etc)
  262.   22      2 bytes number of sectors per FAT (1 or 2)
  263.   24      2 bytes number of sectors per track (8 or 9, 17)
  264.   26      2 bytes number of sides, heads, or cylinders (1 or 2 for floppy)
  265.   28      2 bytes number of special reserved sectors
  266.  
  267.  
  268. THE DATA AREA
  269.  
  270.  Allocation of space for a file (in the data area) is done only when needed 
  271. (it is not preallocated). The space is allocated one cluser (unit allocation) 
  272. at a time. A cluster is always one or more consecutive sector numbers, and all 
  273. of the clusters in a file are "chained" together in the FAT. 
  274.  
  275.  The clusters are arranged on disk to minimize head movement for multisided 
  276. media. All of the space on a track (or cylinder) is allocated before moving 
  277. on to the next track. This is accomplished by using the sequential sector 
  278. numbers on the lowest-numbered head, then all the sector numbers on the next 
  279. head, and so on until all sectors of all heads of the track are used. Then the 
  280. next sector used will be sector 1 of head 0 on the next track.
  281.  
  282.  An interesting innovation that was introduced in MS-DOS 3.0: disk space that 
  283. is freed by erasing a file is not re-used immediately, unlike earlier versions 
  284. of DOS. Instead, free space is obtained from the area not yet used during the 
  285. current session, until all of it is used up. Only then will space that is freed
  286. during the current session be re-used.
  287.  
  288.  This feature minimizes fragmentation of files, since never-before-used space
  289. is always contiguous. However, once any space has been freed by deleting a file,
  290. that advantage vanishes at the next system boot. The feature also greatly
  291. simplifies un-erasing files, provided that the need to do an un-erase is found
  292. during the same session and also provided that the file occupies contiguous 
  293. clusters.
  294.  
  295.  However, when one is using programs which make extensive use of temporary
  296. files, each of which may be created and erased many times during a session,
  297. the feature becomes a nuisance; it forces the permanent files to move farther
  298. and farther into the inner tracks of the disk, thus increasing rather than
  299. decreasing the amount of fragmentation which occurs.
  300.  
  301.  The feature is implemented in DOS by means of a single 16-bit "last cluster
  302. used" (LCU) pointer for each physical disk drive; this pointer is a part of
  303. the physical drive table maintained by DOS. At boot time, the LCU pointer is
  304. zeroed. Each time another cluster is obtained from the free-space pool (the
  305. FAT), its number is written into the LCU pointer. Each time a fresh cluster
  306. is required, the FAT is searched to locate a free one; in older versions of
  307. DOS this search always began at Cluster 0000, but in 3.x it begins at the
  308. cluster pointed to by the LCU pointer.
  309.  
  310.  For hard disks, the size of the file allocation table and directory are 
  311. determined when FORMAT initializes it and are based on the size of the DOS 
  312. partition.
  313.  
  314. The following table gives the specifications for floppy disk formats:
  315.  
  316.                # of   sectors  FAT size    DIR        DIR     sectors  total
  317. disk  DOS ver  sides  /track   (sectors) (sectors) (entries) /cluster sectors
  318.  
  319. (5-1/4 inch)
  320. 160k (DOS 1.0)   1     8  (40)     1        4         64         1      320
  321. 320k (DOS 1.1)   2     8  (40)     1        7         112        2      360
  322. 180k (DOS 2.0)   1     9  (40)     2        4         64         1      640
  323. 360k (DOS 2.0)   2     9  (40)     2        7         112        2      720
  324. 1.2M (DOS 3.0)   2     15 (80)     7        14        224        1      2400
  325.  
  326. (3-1/2 inch)                                                       
  327. 720k (DOS 3.2)   2     9  (80)     3        7         112        2      1440
  328. 1.44M(DOS 3.3)   2     18 (80)     9        14        224        1      2880
  329.  
  330.  Files in the data area are not nescessarily written sequentially on the first.
  331. The data area space is allocated one cluster at a time, skipping over clusters 
  332. already allocated. The first free cluster found is the next cluster allocated, 
  333. regardless of its physical location on the disk. This permits the most efficient
  334. utilization of disk space because clusters freed by erasing files can be 
  335. allocated for new files. Refer back to the description of the DOS FAT in this 
  336. chapter for more information.
  337.  
  338.  
  339. Hard Disk Layout
  340.  
  341.  The DOS hard disk routines perform the following services:
  342.  
  343. 1) Allow multiple operating systems to utilize the hard disk without the need 
  344.    to backup and restore files when changing operating systems.
  345.  
  346. 2) Allow a user-selected operating system to be started from the hard disk.
  347.    
  348.    I) In order to share the hard disk among operating systems, the disk may be 
  349.       logically divided into 1 to 4 partitions. The space within a given 
  350.       partition is contiguous, and can be dedicated to a specific operating 
  351.       system. Each operating system may "own" only one partition in DOS versions
  352.       2.0 through 3.2. PCDOS 3.3 introduced the "Extended DOS Partition" which 
  353.       allows multiple DOS partitions on the same hard disk. The FDISK.COM (or 
  354.       similar program from other DOS vendors) utility allows the user to select
  355.       the number, type, and size of each partition. The partition information is
  356.       kept in a partition table that is embedded in the master fixed disk boot 
  357.       record on the first sector of the disk. The format of this table varies 
  358.       from version to version of DOS.
  359.  
  360.   II) An operating system must consider its partition to be the entire disk, 
  361.       and must ensure that its functions and utilities do not access other 
  362.       partitions on the disk. 
  363.  
  364.  III) Each partition may contain a boot record on its first sector, and any 
  365.       other programs or data that you choose - including a copy of an operating 
  366.       system. For example, the DOS FORMAT command may be used to format and 
  367.       place a copy of DOS in the DOS partition in the same manner that a 
  368.       diskette is formatted. With the FDISK utility, you may designate a 
  369.       partition as "active" (bootable). The master hard disk boot record causes
  370.       that partition's boot record to receive control when the system is started
  371.       or reset. Additional disk partitions could be FORTH, UNIX, Pick, CP/M-86,
  372.       or the UCSD p-System.
  373.  
  374.  
  375.  
  376. SYSTEM INITIALIZATION
  377.  
  378. The boot sequence is as follows:
  379.  
  380. 1. System initialization first attempts to load an operating system from 
  381.    diskette drive A. If the drive is not ready or a read error occurs, it then 
  382.    attempts to read a master hard disk boot record on the first sector of the 
  383.    first hard disk in the system. If unsuccessful, or if no hard disk is 
  384.    present, it invokes ROM BASIC in an IBM PC or displays a disk error 
  385.    message on most compatibles.
  386.  
  387. 2. If initialization is successful, the master hard disk boot record is given 
  388.    control and it examines the partition table embedded within it. If one of 
  389.    the entries indicates an active (bootable) partition, its boot record is 
  390.    read from the partition's first sector and given control.
  391.  
  392. 3. If none of the partitions is bootable, ROM BASIC is invoked on an IBM PC or
  393.     a disk error on most compatibles.
  394.  
  395. 4. If any of the boot indicators are invalid, or if more than one indicator is 
  396.    marked as bootable, the message INVALID PARTITION TABLE is displayed and the 
  397.    system stops.
  398.  
  399. 5. If the partition's boot record cannot be successfully read within five 
  400.    retries due to read errors, the message ERROR LOADING OPERATING SYSTEM 
  401.    appears and the system stops.
  402.  
  403. 6. If the partition's boot record does not contain a valid "signature", the 
  404.    message MISSING OPERATING SYSTEM appears, and the system stops.
  405.  
  406. NOTE: When changing the size or location of any partition, you must ensure that
  407.       all existing data on the disk has been backed up. The partitioning program
  408.       will destroy the data on the disk.
  409.  
  410.  
  411.  
  412. BOOT RECORD/PARTITION TABLE
  413.  
  414.  A boot record must be written on the first sector of all hard disks, and 
  415. must contain the following:
  416.  
  417. 1. Code to load and give control to the boot record for one of four possible 
  418.    operating systems.
  419.  
  420. 2. A partition table at the end of the boot record. Each table entry is 16 
  421.    bytes long, and contains the starting and ending cylinder, sector, and head 
  422.    for each of four possible partitions, as well as the number of sectors 
  423.    preceding the partition and the number of sectors occupied by the partition. 
  424.    The "boot indicator" byte is used by the boot record to determine if one of 
  425.    the partitions contains a loadable operating system. FDISK initialization 
  426.    utilities mark a user-selected partition as "bootable" by placing a value 
  427.    of 80h in the corresponding partition's boot indicator (setting all other 
  428.    partitions' indicators to 0 at the same time). The presence of the 80h tells 
  429.    the standard boot routine to load the sector whose location is contained in 
  430.    the following three bytes. That sector is the actual boot record for the 
  431.    selected operating system, and it is responsible for the remainder of the 
  432.    system's loading process (as it is from the diskette). All boot records are 
  433.    loaded at absolute address 0:7C00.
  434.  
  435. The partition table with its offsets into the boot record is:
  436. (except for Wyse DOS 3.2 with 32 bit allocation table, and DOS 3.3-up)
  437. ┌──────────────────────────────────┬──────────┬──────────┬──────────┬──────────┐
  438. │ Offset   /    Purpose            │          │   Head   │  Sector  │ Cylinder │
  439. ├──────────────────────────────────┼──────────┼──────────┼──────────┼──────────┤
  440. │ 1BEh partition 1 begin           │ boot ind │    H     │    S     │   cyl    │
  441. ├──────────────────────────────────┼──────────┼──────────┼──────────┼──────────┤
  442. │ 1C2h partition 1 end             │ syst ind │    H     │    S     │   cyl    │
  443. ├──────────────────────────────────┼──────────┴──────────┼──────────┴──────────┤
  444. │ 1C6h partition 1 relative sector │      low word       │      high word      │
  445. ├──────────────────────────────────┼─────────────────────┼─────────────────────┤
  446. │ 1CAh partition 1 # sectors       │      low word       │      high word      │
  447. ├──────────────────────────────────┼──────────┬──────────┼──────────┬──────────┤
  448. │ 1CEh partition 2 begin           │ boot ind │    H     │    S     │   cyl    │
  449. ├──────────────────────────────────┼──────────┼──────────┼──────────┼──────────┤
  450. │ 1D2h partition 2 end             │ syst ind │    H     │    S     │   cyl    │
  451. ├──────────────────────────────────┼──────────┴──────────┼──────────┴──────────┤
  452. │ 1D6h partition 2 relative sector │      low word       │      high word      │
  453. ├──────────────────────────────────┼─────────────────────┼─────────────────────┤
  454. │ 1DAh partition 2 # sectors       │      low word       │      high word      │
  455. ├──────────────────────────────────┼──────────┬──────────┼──────────┬──────────┤
  456. │ 1DEh partition 3 begin           │ boot ind │    H     │    S     │   cyl    │
  457. ├──────────────────────────────────┼──────────┼──────────┼──────────┼──────────┤
  458. │ 1E2h partition 3 end             │ syst ind │    H     │    S     │   cyl    │
  459. ├──────────────────────────────────┼──────────┴──────────┼──────────┴──────────┤
  460. │ 1E6h partition 3 relative sector │      low word       │      high word      │
  461. ├──────────────────────────────────┼─────────────────────┼─────────────────────┤
  462. │ 1EAh partition 3 # sectors       │      low word       │      high word      │
  463. ├──────────────────────────────────┼──────────┬──────────┼──────────┬──────────┤
  464. │ 1EEh partition 4 begin           │ boot ind │    H     │    S     │   cyl    │
  465. ├──────────────────────────────────┼──────────┼──────────┼──────────┼──────────┤
  466. │ 1F2h partition 4 end             │ syst ind │    H     │    S     │   cyl    │
  467. ├──────────────────────────────────┼──────────┴──────────┼──────────┴──────────┤
  468. │ 1F6h partition 4 relative sector │      low word       │      high word      │
  469. ├──────────────────────────────────┼─────────────────────┼─────────────────────┤
  470. │ 1FAh partition 4 # sectors       │      low word       │      high word      │
  471. ├──────────────────────────────────┼──────────┬──────────┼─────────────────────┘
  472. │ 1FEh signature                   │  hex 55  │  hex AA  │
  473. └──────────────────────────────────┴──────────┴──────────┘
  474.  
  475.  
  476.  
  477. HARD DISK TECHNICAL INFORMATION
  478.  
  479.  Boot indicator (boot ind): The boot indicator byte must contain 0 for a non- 
  480. bootable partition or 80h for a bootable partition. Only one partition can be 
  481. marked as bootable at a time.
  482.  
  483.  System Indicator (sys ind): The sys ind field contains an indicator of the 
  484. operating system that "owns" the partition.
  485.  
  486.           The system indicators are:
  487.                        00h unknown (unspecified or non-DOS)
  488.                        01h DOS 12 bit FAT
  489.                        02h DOS 16 bit FAT
  490.  
  491.  Cylinder (CYL) and Sector (S): The 1 byte fields labelled CYL contain the low 
  492. order 8 bits of the cylinder number - the high order 2 bits are in the high 
  493. order 2 bits of the sector (S) field. This corresponds with the ROM BIOS 
  494. interrupt 13h (disk I/O) requirements, to allow for a 10 bit cylinder number.
  495.  
  496.  The fields are ordered in such a manner that only two MOV instructions are 
  497. required to properly set up the DX and CX registers for a ROM BIOS call to 
  498. load the appropriate boot record (hard disk booting is only possible from the 
  499. first hard disk in the system, where a BIOS drive number of 80h corresponds 
  500. to the boot indicator byte).
  501.  
  502.  All partitions are allocated in cylinder multiples and begin on sector 1,
  503. head 0.
  504.  
  505.  EXCEPTION: The partition that is allocated at the beginning of the disk starts 
  506. at sector 2, to account for the hard disk's master boot record.
  507.  
  508.  Relative Sector (rel sect): The number of sectors preceding each partition 
  509. on the disk is kept in the 4 byte field labelled "rel sect". This value is 
  510. obtained by counting the sectors beginning with cylinder 0, sector 1, head 0 
  511. of the disk, and incrementing the sector, head, and then track values up to 
  512. the beginning of the partition. This, if the disk has 17 sectors per track and 
  513. 4 heads, and the second partition begins at cylinder 1, sector 1, head 0,and 
  514. the partition's starting relative sector is 68 (decimal) - there were 17 
  515. sectors on each of 4 heads on 1 track allocated ahead of it. The field is stored
  516. with the least significant word first.
  517.  
  518.  Number of sectors (#sects): The number of sectors allocated to the partition 
  519. is kept in the "# of sects" field. This is a 4 byte field stored least 
  520. significant word first.
  521.  
  522.  Signature: The last 2 bytes of the boot record (55AAh) are used as a signature
  523. to identify a valid boot record. Both this record and the partition boot record 
  524. are required to contain the signature at offset 1FEh.
  525.  
  526.  The master disk boot record invokes ROM BASIC if no indicator byte reflects a 
  527. bootable system.
  528.  
  529.  When a partition's boot record is given control. It is passed its partition 
  530. table entry address in the DS:SI registers.
  531.  
  532.  
  533.  
  534. DETERMINING FIXED DISK ALLOCATION
  535.  
  536. DOS determines disk allocation using the following formula:
  537.               
  538.                                          D * BPD
  539.                             TS - RS -  ───────────
  540.                                            BPS
  541.                       SPF = ──────────────────────────────
  542.                                         BPS * SPC
  543.                                  CF + ──────────────
  544.                                            BPC
  545. where:
  546.  
  547.      TS      total sectors on disk
  548.      RS      the number of sectrs at the beginning of the disk that are reserved
  549.              for the boot record. DOS reserves 1 sector.
  550.      D       The number of directory entries in the root directory.
  551.      BPD     the number of bytes per directory entry. This is always 32.
  552.      BPS     the number of bytes per logical sector. Typically 512, but you can
  553.              specify a different number with VDISK.
  554.      CF      The number of FATS per disk. Usually 2. VDISK is 1.
  555.      SPF     the number of sectors per FAT. Maximum 64.
  556.      SPC     The number of sectors per allocation unit.
  557.      BPC     the number of bytes per FAT entry. BPC is 1.5 for 12 bit FATs.
  558.              2 for 16 bit FATS.
  559.  
  560.  
  561. To calculate the minimum partition size that will force a 16-bit FAT:
  562.  
  563.         CYL = (max clusters * 8)/(HEADS * SPT)
  564.  
  565. where:
  566.      CYL     number of cylinders on the disk
  567.      max clusters  4092 (maximum number of clusters for a 12 bit FAT)
  568.      HEADS   number of heads on the hard disk
  569.      SPT     sectors per track  (normally 17 on MFM)
  570.  
  571.  
  572. note: DOS 2.0 uses a "first fit" algorithm when allocating file space on the 
  573. hard disk. Each time an application requests disk space, it will scan from the 
  574. beginning of the FAT until it finds a contiguous peice of storage large enough 
  575. for the file.
  576.  DOS 3.0 keeps a pointer into the disk space, and begins its search from the 
  577. point it last left off. This pointer is lost when the system is rebooted. 
  578. This is called the "next fit" algorithm. It is faster than the first fit and 
  579. helps minimize fragmentation.
  580.  In either case, if the FCB function calls are used instead of the handle 
  581. function calls, the file will be broken into peices starting with the first 
  582. availible space on the disk.
  583.  
  584.  
  585. Comment to 826. Comment(s). 
  586. ----------
  587. Better late than never...
  588. A partition table entry for the IBM AT is set up as follows:
  589.  
  590.         DB      drive   ; 0 or 80H, 80H marks a bootable, active partition
  591.         DB      head1   ; starting heads
  592.         DW      trksec1 ; starting track/sector (CX value for INT 13)
  593.         DB      system  ; see below
  594.         DB      head2   ; ending head
  595.         DW      trksec2 ; ending track/sector
  596.         DD      sector1 ; absolute # of starting sector
  597.         DD      sector2 ; absolute # of last sector
  598.  
  599. The system byte is different for different O/S entries:
  600.  
  601.         1      DOS, 12-bit FAT entries
  602.         4      DOS, 16-bit FAT entries
  603.         DB     Concurrent DOS
  604.         F2     2nd partition for Sperry machines with large disks
  605.  
  606.         And so on.  There are bytes for XENIX, Prologue and lots of other O/S. 
  607. Many manufacturers diddle with these system bytes to implement more than 1 DOS
  608. partition per disk.  The only one I know about who violates the rule that only
  609. one DOS partition (1 or 4) per disk may exist is Tandon. 
  610.  
  611.  
  612.